package com.cr.mrapp.Controller.rest;

import com.cr.mrapp.entity.Item;
import com.cr.mrapp.entity.Order;
import com.cr.mrapp.entity.OrderDetail;
import com.cr.mrapp.entity.Staff;
import com.cr.mrapp.result.R;
import com.cr.mrapp.result.ResponseData;
import com.cr.mrapp.service.ItemService;
import com.cr.mrapp.service.OrderService;
import com.cr.mrapp.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private ItemService itemService;
    @Autowired
    private StaffService staffService;
    @Autowired
    private OrderService orderService;

    @RequestMapping("/item/list.do")
    public ResponseData findItem(int page , int limit, String itemType){
        List<Object> itemList = itemService.findByPage(page, limit, itemType);
        return R.ok(itemList);
    }

    @RequestMapping("/item/detail.do")
    public  ResponseData findItemDetail(int id){
        Item item = itemService.findById(id);
        return R.ok(item);
    }

    @RequestMapping("/order/add.do")
    public  ResponseData addOrder(@RequestBody Order order){
        int row = orderService.add(order);
        return R.ok(row);
    }

    @RequestMapping("/order/findMyOrder.do")
    public ResponseData findMyOrder(String customerName){
        List<OrderDetail> orderDetails = orderService.findMyOrder(customerName);
        return R.ok(orderDetails);
    }

    @RequestMapping("/staff/list.do")
    public ResponseData findStaff(int page , int limit, String staffName){
        List<Object> staffList = staffService.findByPage(page, limit, staffName);
        return R.ok(staffList);
    }

    @RequestMapping("/staff/detail.do")
    public  ResponseData findStaffDetail(int id){
        Staff staff = staffService.findById(id);
        return R.ok(staff);
    }

    @RequestMapping("/staff/selectStaffList.do")
    public ResponseData selectStaff(int storeId){
        List<Object> selectStaffList = staffService.findByStoreId(storeId);
        return R.ok(selectStaffList);
    }
}
